<?php
namespace app\index\controller;
use think\Db;
use app\common\lib;

class Index extends Base
{
    public function index()
    {
        if(request()->isAjax()){
            $isLogin = lib\Tools::isIndexLogin();
            $msg = [
                'msg' => '必须本小区业主登录后才可使用！'
            ];
            if(!$isLogin) {
                return show('200','0',$msg);
            }
            $car_number = request()->param('car_number');
            $data = [
                'username' => '该车主未注册',
                'car_number' => '车牌未注册',
                'tel'   => '无'
            ];
            $car_msg = Model('Car')
                            ->join('bd_home ',' bd_car.user_id = bd_home.id')
                            ->field('bd_home.username,bd_home.tel,bd_car.car_number')
                            ->where(['car_number'=>$car_number])
                            ->find();
            if(!$car_msg) {
                return show('200','1',$data);
            }
            $data = [
                'username' => $car_msg['username'],
                'car_number' => $car_msg['car_number'],
                'tel'   => $car_msg['tel'],
            ];
            return show('200','1',$data);
        }else {
            $this->assign([
                'is_ios'=>is_ios()
            ]);
            return $this->fetch();
        }
    }
}
